package com.Data;


import android.os.AsyncTask;
import com.Managers.UserManagerClass;
import com.SoapClasses.SoapPost_Follows;


public class Follow extends AsyncTask<Integer, String, Boolean> {

    public final static int ACTION_ADD = 1;

    public final static int ACTION_CHECK = 0;

    public final static int ACTION_DELETE = 2;

    private onAddFollowerCompleted callbackAddFollow;

    private onDeleteFollowerCompleted callbackDeleteFollow;

    private onGetFollowCompleted callbackGetFollow;

    private int UserId;

    public interface onAddFollowerCompleted {

        void Completed();
    }

    public interface onDeleteFollowerCompleted {

        void Completed();
    }

    public interface onGetFollowCompleted {

        void Completed(Boolean result);
    }

    public Follow(int userId) {

        super();
        UserId = userId;
    }

    public onAddFollowerCompleted getCallbackAddFollow() {

        return callbackAddFollow;
    }

    public onDeleteFollowerCompleted getCallbackDeleteFollow() {

        return callbackDeleteFollow;
    }

    public onGetFollowCompleted getCallbackGetFollow() {

        return callbackGetFollow;
    }

    public void setCallbackAddFollow(onAddFollowerCompleted callbackAddFollow) {

        this.callbackAddFollow = callbackAddFollow;
    }

    public void setCallbackDeleteFollow(onDeleteFollowerCompleted callbackDeleteFollow) {

        this.callbackDeleteFollow = callbackDeleteFollow;
    }

    public void setCallbackGetFollow(onGetFollowCompleted callbackGetFollow) {

        this.callbackGetFollow = callbackGetFollow;
    }

    @Override
    protected Boolean doInBackground(Integer... action) {

        String[] data = new String[2];
        data[0] = String.valueOf(UserManagerClass.UserLogged.getID());
        data[1] = String.valueOf(this.UserId);
        SoapPost_Follows sf = new SoapPost_Follows();
        switch (action[0]) {
            case ACTION_CHECK:
                sf = new SoapPost_Follows();
                String res = sf.isFollowed(data);
                return res.equals("1");
            case ACTION_DELETE:
                sf.deleteFollow(data);
                return true;
            case ACTION_ADD:
                sf.addFollow(data);
                return true;
            default:
                return false;
        }

    }

    @Override
    protected void onPostExecute(Boolean result) {

        if (callbackGetFollow != null)
            callbackGetFollow.Completed(result);
        if (callbackAddFollow != null)
            callbackAddFollow.Completed();
        if (callbackDeleteFollow != null)
            callbackDeleteFollow.Completed();
    }

}
